#include "Arduino.h"


#define LED1 2 //定义led1脚位常量
#define LED2 3 //定义led2脚位常量



#define INPUT_BUTTON1 A4 //定义输入脚位
#define INPUT_BUTTON2 A5 //定义输入脚位

unsigned long nowtime1 = 0;
unsigned long nowtime2 = 0;

bool check_button1 = false; //检测是否按下按钮
bool check_button2 = false; //检测是否按下按钮
// 初始化
void setup() {
  // 串口输出 设置波特率
  Serial.begin(115200);

  // 按钮初始化
  pinMode(INPUT_BUTTON1, INPUT_PULLUP);
  pinMode(INPUT_BUTTON2, INPUT_PULLUP);

  //初始化led1-led3灯为输出模式以及低电平
  pinMode(LED1, OUTPUT);
  pinMode(LED2, OUTPUT);

  digitalWrite(LED1, LOW);
  digitalWrite(LED2, LOW);

  //串口打印输出信息
  Serial.println("初始化完成.");
}



//循环程序开始
void loop() {


  //按钮判断是否按下去
  if (digitalRead(INPUT_BUTTON1) == LOW) {
    check_button1 = true;
  }
  if (digitalRead(INPUT_BUTTON2) == LOW) {
    check_button2 = true;
  }



  if ( check_button1 == true) {
    digitalWrite(LED1, HIGH);
    if ((unsigned long)(millis() - nowtime1) > 5000) {
      nowtime1 = millis();
      digitalWrite(LED1, LOW);
      Serial.println("led1 off");
      check_button1 = false;
    }
  }
  
  if ( check_button2 == true) {
    digitalWrite(LED2, HIGH);
    if ((unsigned long)(millis() - nowtime2) > 10000) {
      nowtime2 = millis();
      digitalWrite(LED2, LOW);
      Serial.println("led2 off");
      check_button2 = false;
    }

    //delay(10);
  }
}
